const state = {
	cartList:[]
}
const mutations = {
	JOIN_CART(state,goods){
		// 判断购物车中是否有该商品
		const info = state.cartList.find(v=>v.goodsName===goods.goodsName);
		if(info){
			info.buyNum++;
		}else{
			state.cartList.unshift({
				...goods,
				buyNum:1
			})
		}
	}
}
const getters = {
	sumPrice(state){
		return state.cartList.reduce((sum,item)=>{

			sum+=item.buyNum*item.goodsPrice;
			return sum;
		},0)
	}
}
export default {
	state,
	mutations,
	getters
}